<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.text.DecimalFormat" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>梯形面积结果</title>
</head>
<body>
<%
    // 获取表单参数
    String topBaseStr = request.getParameter("upperBase");
    String bottomBaseStr = request.getParameter("lowerBase");
    String heightStr = request.getParameter("height");

    // 将字符串转换为double类型
    double upperBase = Double.parseDouble(topBaseStr);
    double lowerBase = Double.parseDouble(bottomBaseStr);
    double height = Double.parseDouble(heightStr);

    // 使用PageContext作为Bean工厂
    PageContext pageContext = request.getPageContext();
    DecimalFormat df = new DecimalFormat("#.00"); // 设置数值格式

    // 创建梯形对象并计算面积
    Trapezoid trapezoid = new Trapezoid(upperBase, lowerBase, height);
    double area = trapezoid.calculateArea();

    // 在JSP页面中显示梯形的参数和面积
    out.println("<p>梯形的上底是: " + upperBase + "</p>");
    out.println("<p>梯形的下底是: " + lowerBase + "</p>");
    out.println("<p>梯形的高是: " + height + "</p>");
    out.println("<p>梯形的面积是: " + df.format(area) + " 平方单位</p>");
%>
</body>
</html>